<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript">
        window.onload = function () {
            var rows = document.getElementById('tbl').tBodies[0].rows;
            for (var i = 0; i < rows.length; i++) {
                //给每个tr标签进行动态事件绑定
                rows[i].onmouseover = function () {
                    //this关键字 代表触发事件的元素
                    this.style.backgroundColor = 'red';
                };
                rows[i].onmouseout = function () {
                    this.style.backgroundColor = 'white';
                };
            }
        }
    </script>
</head>
<body>
<body>
<table border="1" width="500" height="50" align="center" id="tbl">
    <thead>
    <tr>
        <th>编号</th>
        <th>姓名</th>
        <th>年龄</th>
    </tr>
    </thead>
    <tbody>
    <tr>
        <td>1</td>
        <td>张三</td>
        <td>22</td>
    </tr>
    <tr>
        <td>2</td>
        <td>李四</td>
        <td>25</td>
    </tr>
    <tr>
        <td>3</td>
        <td>王五</td>
        <td>27</td>
    </tr>
    <tr>
        <td>4</td>
        <td>赵六</td>
        <td>29</td>
    </tr>
    <tr>
        <td>5</td>
        <td>田七</td>
        <td>30</td>
    </tr>
    <tr>
        <td>6</td>
        <td>汾九</td>
        <td>20</td>
    </tr>
    </tbody>
</table>
</body>

</html>